<?php

namespace App\Console\Commands\Fee;

use App\Models\Fee\FeeAnnualOrderModel;
use Illuminate\Console\Command;

class FixFeeOrderPayStatus extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'fee:fix-fee-order-pay-status';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '修复年费订单未支付和已支付的情况（根据应付和实付）';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        FeeAnnualOrderModel::query()
            ->get()
            ->map(function ($item){
                //应付年费
                $shouldPrice = $item->shouldPayPrice;
                //已付年费
                $payPrice = $item->payPrice;
                //通过应付年费与已付年费的比较修改支付状态   修复导入支付记录的状态修改
                if ($shouldPrice == $payPrice) {
                    $item->payStatus = FeeAnnualOrderModel::PAY_STATUS_OK;
                } elseif ($payPrice > 0) {
                    $item->payStatus = FeeAnnualOrderModel::PAY_STATUS_PART;
                } else {
                    $item->payStatus = FeeAnnualOrderModel::PAY_STATUS_WAIT;
                }
                $item->save();
                dump($item->shopId);
            });
    }
}
